const connection = require('../app/database');

class FileService {
    // 创建文件记录
    async created(filename, mimetype, size, id) {
        try {
            // 拼接 SQL 语句
            const statement = 'INSERT INTO avatar (filename, mimetype, size, user_id) VALUES (?,?,?,?);';

            // 执行 SQL 语句
            const [result] = await connection.execute(statement, [filename, mimetype, size, id]);

            return result;
        } catch (error) {
            console.error('FileService - created:', error);
            throw error; // 抛出异常，让调用者处理
        }
    }
}

module.exports = new FileService();
